<template>
  <div>
    <!--    类似login.vue，参考login.vue的注释    -->
    <el-card class="box-card" style="width: 400px;margin: 0 auto;text-align: center;">
      <div slot="header" class="clearfix">
        <span>注册</span>
      </div>
      <el-form inline>
        <el-form-item label="账号">
          <el-input v-model="user.account"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="密码">
          <el-input v-model="user.password"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="姓名">
          <el-input v-model="user.name"></el-input>
        </el-form-item>
        <br>
        <el-form-item>
          <el-button @click="register">注册</el-button>
          <el-button type="text" @click="$router.push('/login')">已有帐号？去登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "register",
  data() {
    return {
      user: {}
    }
  },
  methods: {
    register() {
      this.$axios.post('/api/user/register', this.user)
          .then((res) => {
            if (res.data.status === 201) {
              this.$message.success(res.data.message);
              this.$router.push('/login');
            } else {
              this.$message.error(res.data.message);
            }
          })
    }
  }
}

</script>

<style scoped>

</style>